<?php
/**
 * Created by PhpStorm.
 * User: CQH
 * Date: 2017\9\20
 * Time: 11:49
 */

namespace app\common\model;


use think\Model;
use think\db;

/**
 * Class CustomerLog
 * @package app\common\model
 *      操作用户记录表  模型
 */
class CustomerLog extends Model
{
	protected $db;

	public function __construct()
	{
	    parent::__construct();
		$this->db = Db::name("Customer_log");
	}
    
	/**
	 * 操作用户记录表增加一条数据
	 * @param $data  ->  数组   ['key' => 'value']
	 * @return bool
	 */
	public function insertOne($data)
	{
		//$this->data($data);
		$result = $this->db->insert($data);
		// 判断结果 并返回
		if ($result !== 1) {
			return false;
		}
		return $result;
	}
    
	/**
	 * 根据 user_id (customer_id) 获取所有的数据
	 * @return bool|false|\PDOStatement|string|\think\Collection
	 */
	public function getList($where,$order="add_time desc",$limit=5)
	{
		$join = [
            ['rq_customer','rq_customer.user_id = rq_customer_log.customer_id','left'],
        ];
		$file = "rq_customer_log.*,rq_customer.username";
	    $userInfo = Db::name('customer_log')
                        ->where($where)
                        ->join($join)
                        ->field($file)
                        ->order($order)
                        ->limit($limit)
                        ->select();

//            $this->db->join($join)->where($where)->field($file)->cache(true)->order($order)->limit($limit)->select();
//	    echo Db::name('customer_log')->getLastSql();die();
//	    	    dump($userInfo);die();
		// 判断结果 并返回
		if ($userInfo == false) {
			return false;
		}
		return $userInfo;
	}

}